import axios from 'axios';

import { Toast } from 'antd-mobile';

axios.interceptors.request.use(
  (config) => {
    Toast.show({
      icon: 'loading',
      content: '加载中…',
      duration: 0,
      maskClickable: false,
    });
    // Do something before request is sent
    return config;
  },
  (error) => {
    Toast.show({
      icon: 'fail',
      content: '出错了！',
    });
    // Do something with request error
    return Promise.reject(error);
  }
);

axios.interceptors.response.use(
  (response) => {
    Toast.clear();
    // Do something with response data
    return response;
  },
  (error) => {
    Toast.show({
      icon: 'fail',
      content: '出错了！',
    });
    // Do something with response error
    return Promise.reject(error);
  }
);
